<?php 

namespace Wechat\Controller;
use Think\Controller;

class IndexController extends Controller {

	/**
	 * 公众号列表页
	 * @author 艾逗笔<765532665@qq.com>
	 */
	public function lists() {
		$res['title'] = '公众号列表';
		$res['url'] = U('lists');
		$res['class'] = 'active';
		$nav[] = $res;
		$this->assign('nav', $nav);

		$lists = M('wechat')->order('add_time desc')->select();
		$this->assign('lists', $lists);
		$this->display();
	}

	/**
	 * 新增公众号
	 * @author 艾逗笔<765532665@qq.com>
	 */
	public function add() {
		if (IS_AJAX) {
			$Wechat = D('Wechat');
			if (!$Wechat->create()) {
				$return['rsm'] = null;
				$return['errno'] = -1;
				$return['err'] = $Wechat->getError();
			} else {
				$Wechat->add();
				$return['rsm'] = array('url'=>U('lists'));
				$return['errno'] = 1;
				$return['err'] = '新增公众号成功';
			}
			
			$this->ajaxReturn($return);
		}

		$res['title'] = '公众号列表';
		$res['url'] = U('lists');
		$res['class'] = '';
		$nav[] = $res;

		$res['title'] = '新增公众号';
		$res['url'] = U('add');
		$res['class'] = 'active';
		$nav[] = $res;
		$this->assign('nav', $nav);
		$this->display();
	}

	/**
	 * 公众号管理首页
	 * @author 艾逗笔<765532665@qq.com>
	 */
	public function index() {
		$this->display();
	}
}

 ?>